# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=openvas-scanner
pkgver=21.4.4
pkgrel=2
pkgdesc="Open Vulnerability Assessment Scanner"
url="https://openvas.org/"
arch="all !x86 !armhf !armv7" # Fails to build, see #12616
license="GPL-2.0-only"
depends="redis nmap coreutils openssl util-linux"
install="$pkgname.post-install"
pkgusers="gvm"
pkggroups="gvm"
checkdepends="cppcheck"
makedepends="cmake bison gvm-libs-dev glib-dev libgcrypt-dev
	doxygen xmltoman graphviz libpcap-dev gpgme-dev
	clang-dev libssh-dev libksba-dev net-snmp-dev
	linux-headers glibmm-dev"

case $CARCH in
        x86|x86_64) makedepends="$makedepends openvas-smb-dev";;
esac

subpackages="$pkgname-doc $pkgname-config"
source="$pkgname-$pkgver.tar.gz::https://github.com/greenbone/openvas/archive/v$pkgver.tar.gz
	execinfo-musl-fix.patch
	malloc-trim.patch
	tcp_mss_include.patch
	fix-redis-dbpath.patch
	openvas-sysctl.conf
	greenbone-nvt-sync.cron
	greenbone-data-sync.cron"
options="!check" # dependency tree not available outside x86

prepare() {
	default_prepare
	mkdir build
}

build() {
	cd build
	cmake -DCMAKE_BUILD_TYPE=Release \
		-DSBINDIR=/usr/bin \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DSYSCONFDIR=/etc \
		-DLOCALSTATEDIR=/var \
		-DOPENVAS_RUN_DIR=/run/ospd \
	..
	make
}

check() {
	cd build
	make check
}

package() {
	cd build
	make DESTDIR="$pkgdir" install
	chown $pkgusers "$pkgdir"/etc/openvas
	chown $pkgusers "$pkgdir"/var/log/gvm
	chown $pkgusers "$pkgdir"/var/lib/openvas
	chown $pkgusers "$pkgdir"/var/lib/openvas/plugins
}

config() {
	pkgdesc="Configuration files and scripts for openvas"
	install -Dm644 "$builddir"/config/redis-openvas.conf "$subpkgdir"/etc/redis-openvas.conf
	install -Dm644 "$srcdir"/openvas-sysctl.conf "$subpkgdir"/etc/sysctl.d/02-openvas.conf
	install -Dm600 -g "$pkggroups" "$srcdir"/greenbone-nvt-sync.cron \
		"$subpkgdir"/etc/crontabs/gvm
	install -Dm744 "$srcdir"/greenbone-data-sync.cron \
		"$subpkgdir"/etc/periodic/daily/greenbone-data-sync
}

sha512sums="
f2fe1f802b14fc41ee0d7657d031d318b651c3ec9ef554b33379a7459d40c17b44525c8f666ccb9670868576c101766936dd0c700778e46683bf43f0683834b6  openvas-scanner-21.4.4.tar.gz
468489f234689b9043451e1af65cfcdfbd59d6561bfff42f09171f0d3773594403c4c8335cc760b315947d225ed60781d0b65ce6f30875471a8d6abec4a4b20f  execinfo-musl-fix.patch
dd2e082435b2b664fe32306d582cbfb9f12d51d21f3689bc3e99a6ff1cc33a8929cfe5b475cf43dcb4418be60cb2934ec55ad01365e947a88c53a086b6333b28  malloc-trim.patch
7eeb50374d7812aef6651517f79ce8f4dd3769a64feaf3e6a1e29089d22ae10033ddedd38b7f7671b83421d354104effeeefd44df2811e07075fe3450f02954c  tcp_mss_include.patch
1cb7c12bf23af7c5938834feb109e4d2858f57be68fb31c69df8bece44abe5f7b64fa4a5cfc1dac1c990c87e38db306ce3b8bef0dc9e247b40dae8afbd8c0c16  fix-redis-dbpath.patch
1b85a5511e73a79bc2c9e11e773fee4d641a2f55760eb8e3f4a41cc0d73007e2f6300832c35dd2408838eb42efef54ba6e238a0ed551e34d21becc2aef499991  openvas-sysctl.conf
e721ba637aa8ec4ee8dc0a703e3ea681bd2bc89057afe39995c9b09711991e2f45b9a0d26a985dd59da65067f3e8b1bd8ebc6ae076331eb168362ace3061cf00  greenbone-nvt-sync.cron
83230f6d1dc35d7816fc7a62f70bc0bdbe2d553c8ae00fb45bfc2426cb4694893d90cfb8f1c26d972c4d20b1696be1c11108220d3fe032beafafcc9cc115a067  greenbone-data-sync.cron
"
